package config.ioc;

import com.dao.UserDao;
import com.dao.UserDaoImpl;
import com.service.UserService;
import com.service.UserServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@ImportResource
@Configuration()
public class HelloIocConfig {

    @Bean
    public UserDao userDao() {
        System.out.println("bean方法：注册userDao");
        return new UserDaoImpl();
    }

    @Bean
    public UserService userService() {

        UserServiceImpl userService = new UserServiceImpl();
        //new UserDaoImpl();
        //bean间调用来完成依赖注入
        userService.setDao(userDao());
        return userService;
    }
}
